package cn.edu.uestc.smgt.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.uestc.smgt.common.Status;
import cn.edu.uestc.smgt.dao.UserMapper;
import cn.edu.uestc.smgt.pojo.User;

@Service
public class UserService {

	@Autowired
	private UserMapper userMapper;

	/**
	 * 
	 * @param username
	 * @param password
	 * @param role
	 * @return {@link Status}.USER_IS_NULL 用户名或密码错误 {@link Status}
	 *         .ROLE_NOT_MATCH 角色不匹配 {@link Status}.SUCCESS 登录成功
	 */
	public int checkUser(String username, String password, String role) {
		User user = new User();
		user.setLoginName(username);
		user.setPwd(password);
		Byte role1 = Byte.parseByte(role);
		User getUser = userMapper.selectByLogin(user);
		if (getUser == null) {
			return Status.USER_IS_NULL;
		}
		if (getUser.getRole() != role1) {
			return Status.ROLE_NOT_MATCH;
		}
		return Status.SUCCESS;
	}
}
